Workflow Retry Template
The Workflow Retry template demonstrates how BindAI can retry failed workflow-node execution before ultimately failing the workflow. Retry behavior is implemented by the workflow executor. When a node raises an exception and a retry policy is configured, the executor re-executes that node until it succeeds or the configured attempt limit is reached. The current implementation provides basic executor-level retry handling. Retry delays and exponential backoff are not yet applied.Purpose
This template demonstrates how to:- Configure a retry policy
- Retry failed node execution
- Limit repeated attempts
- Continue workflow execution after successful recovery
- Handle final workflow failure
- Understand the limitations of the current retry implementation
Workflow Structure
Retry is handled by the executor rather than by a separate workflow branch. Conceptually:RetryPolicy
The retry configuration is represented byRetryPolicy:
The executor uses
max_attempts when deciding whether to retry a failed node.
The existence of a policy field does not mean that the corresponding behavior is implemented.
Retry Policy Defaults
RetryPolicy is a dataclass with these defaults:
max_attempts affects retry decisions. The policy does not itself execute nodes, wait between attempts, or calculate backoff intervals.
Execution Flow
When a node executes successfully:Retry Lifecycle
For:max_attempts represents the maximum number of failed attempts handled by this retry mechanism before failure, assuming the exception reaches the retry handler each time. It is not three additional retries after an initial attempt.
For example, with max_attempts=3, the executor can attempt the node up to three times. If the first attempt fails and the second succeeds, execution continues after the second attempt.
Retry Counter
The workflow context tracks the current retry attempt using:Successful Recovery
A retry can recover from a temporary node failure. For example:Retry Without a Policy
If a node raises an exception and no retry policy is configured:context.retry_policy is None.
Retry Limit
Themax_attempts field controls the limit used by the executor.
For example:
Retry Behavior in the Executor
The executor follows this simplified pattern:Delay Configuration
The retry policy contains:Exponential Backoff
The policy also contains:exponential_backoff field is not currently active. Do not rely on it to increase the interval between retry attempts.
Exception Handling
The current retry mechanism catches exceptions raised during node execution. There is no exception-type filter in the currentRetryPolicy. When a policy is configured, exceptions caught by this handler are subject to the same retry-attempt logic regardless of exception class.
There is no current configuration such as:
RetryPolicy.
Applications should not assume that only transient or explicitly selected exception types will be retried.
Retry vs Loop
Retry and Loop solve different problems.
Use Retry for failure recovery. Use Loop for intentional iteration.
Retry and Parallel Workflows
Retry behavior is implemented by the workflow executor rather than byParallelNode itself.
Conceptually, a workflow might contain parallel branches:
Retry and Timeout
Retry and timeout policies serve different purposes:- Retry handles exceptions raised during node execution.
- Timeout checks elapsed workflow time during execution.
fail_workflow field is not currently used by the executor.
Final Failure
When the retry limit is reached, the executor invokes its normal workflow failure handling. That failure path is responsible for recording the failure and producing an unsuccessful workflow result. The exact persistence, event, and compensation behavior depends on the executor’s failure-handling implementation. Retry itself does not provide durable job recovery, distributed execution, or a guarantee that external side effects can be undone. If your application depends on specific failure events, persistence behavior, or compensation callbacks, verify those behaviors against the relevant runtime implementation.Failure Without Retries
A node failure without a retry policy follows the normal failure path:Example Workflow
A conceptual retry workflow looks like:Safe Retry Considerations
Retrying a node means executing its operation again. This is important for operations that have side effects. For example, these operations may not always be safe to repeat:- Sending an email
- Creating a payment
- Creating a database record
- Submitting an order
- Calling an external API that changes state
Best Practices
- Set
max_attemptsdeliberately. - Understand that the limit controls the number of attempts handled by the retry loop.
- Retry operations only when repeating them is safe.
- Consider idempotency for external side effects.
- Do not assume
delay_secondscauses a delay. - Do not assume
exponential_backoffis active. - Remember that the current policy does not filter exception types.
- Do not treat workflow timeout as a hard interruption of a running node.
- Test both successful recovery and exhausted retries.
- Verify failure and compensation behavior for workflows that depend on it.
Related Templates
The Retry template may be relevant to workflows that also use:08.3 workflow-loop.md08.4 workflow-parallel.md08.7 workflow-timeout.md08.8 workflow-schedule.md
Summary
The Workflow Retry template demonstrates executor-level retry handling for failed workflow-node execution. When a node raises an exception and aRetryPolicy is configured, BindAI retries the node until it succeeds or the configured attempt limit is reached.
The current RetryPolicy contains:
max_attempts currently affects retry execution. Retries happen immediately, and delay, exponential backoff, and exception-type filtering are not implemented.
The current implementation provides basic attempt-limit handling, which can be extended later with delayed retries, backoff, and more selective retry behavior.